
#ifndef __ERRLOG_H_
#define __ERRLOG_H_      1

#include <stddef.h>
#include <stdarg.h>

/****************************************************************************
 *                               log                                        *
 ****************************************************************************/

#ifdef	__cplusplus
extern "C" {
#endif


void InitLogfile(const char *log_fn);
void AppendLogfile(const char *log_fn);
int RenameLogfile(const char *newlog_fn);
int IsLogfileTemp(void);
void CloseLogfile(void);

char *GetLogfilePath(char *buf, size_t n);

void PrintLog(const char *logfmt, ...)
__attribute__((format(printf, 1, 2)));

static inline void PrintLogNorm(const char *expr, const char *nname, double nval) {
    PrintLog("    || %10s ||%-20s = %e\n", expr, nname, nval);
}

void PrintLogLine(size_t len, int c);
void TurnLogOn(void); /* turns logging on */
void TurnLogOff(void); /* turns logging off */

#ifndef LOGDEBUG
#define LOGDEBUG   0
#endif

#if LOGDEBUG
#define PrintLogdbg(expr)         PrintLog expr
#else
#define PrintLogdbg(expr)         (void) 0
#endif


/****************************************************************************
 *                         error                                            *
 ****************************************************************************/

void error_msg(const char *errfmt, ...)
__attribute__((noreturn, format(printf, 1, 2)));

void warning_msg(const char *warnfmt, ...)
__attribute__((format(printf, 1, 2)));

#ifdef	__cplusplus
}
#endif


#endif

